package com.ruoyi.project.declaration.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.declaration.domain.FileList;
import com.ruoyi.project.declaration.domain.Files;
import com.ruoyi.project.declaration.domain.ProjectRecord;
import com.ruoyi.project.declaration.mapper.ProjectRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.declaration.mapper.ProjectMapper;
import com.ruoyi.project.declaration.domain.Project;
import com.ruoyi.project.declaration.service.IProjectService;

/**
 * 工程认证申报数据Service业务层处理
 * 
 * @author Daniel
 * @date 2020-03-24
 */
@Service
public class ProjectServiceImpl implements IProjectService 
{
    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private ProjectRecordMapper projectRecordMapper;

    /**
     * 查询工程认证申报数据
     * 
     * @param pId 工程认证申报数据ID
     * @return 工程认证申报数据
     */
    @Override
    public Project selectProjectById(Long pId)
    {
        return projectMapper.selectProjectById(pId);
    }

    /**
     * 查询工程认证申报数据列表
     * 
     * @param project 工程认证申报数据
     * @return 工程认证申报数据
     */
    @Override
    public List<Project> selectProjectList(Project project)
    {
        return projectMapper.selectProjectList(project);
    }

    /**
     * 新增工程认证申报数据
     * 
     * @param project 工程认证申报数据
     * @return 结果
     */
    @Override
    public int insertProject(Project project)
    {
        int res=projectMapper.insertProject(project);
        ProjectRecord pr=new ProjectRecord();
        pr.setpId(project.getpId());
        pr.setpName(project.getpName());
        pr.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        pr.setUserName(SecurityUtils.getLoginUser().getUser().getUserName());
        pr.setPrName("新增工程");
        pr.setPrContent("新增工程");
        projectRecordMapper.insertProjectRecord(pr);
        return res;
    }

    /**
     * 修改工程认证申报数据
     * 
     * @param project 工程认证申报数据
     * @return 结果
     */
    @Override
    public int updateProject(Project project)
    {
        //插入历史记录
        ProjectRecord pr=new ProjectRecord();
        pr.setpId(project.getpId());
        pr.setpName(project.getpName());
        pr.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        pr.setUserName(SecurityUtils.getLoginUser().getUser().getUserName());
        pr.setPrName(project.getPrName());
        pr.setPrContent(project.getPrContent());
        projectRecordMapper.insertProjectRecord(pr);
        return projectMapper.updateProject(project);
    }

    /**
     * 批量删除工程认证申报数据
     * 
     * @param pIds 需要删除的工程认证申报数据ID
     * @return 结果
     */
    @Override
    public int deleteProjectByIds(Long[] pIds)
    {
        return projectMapper.deleteProjectByIds(pIds);
    }

    /**
     * 删除工程认证申报数据信息
     * 
     * @param pId 工程认证申报数据ID
     * @return 结果
     */
    @Override
    public int deleteProjectById(Long pId)
    {
        return projectMapper.deleteProjectById(pId);
    }
}
